#include "collision.h"

#include "utils.h"

#include<algorithm>
using std::min;
using std::max;

//! Constructor
Collision::Collision() {
}

//! Collision between Bounding Volumes
bool Collision::collision(pair<Point3D, Point3D> bv1, pair<Point3D, Point3D> bv2) {
	pair<Point3D, Point3D> res;
	// X
	res.first.x = max( bv1.first.x, bv2.first.x );
	res.second.x = min( bv1.second.x, bv2.second.x );
	// Y
	res.first.y = max( bv1.first.y, bv2.first.y );
	res.second.y = min( bv1.second.y, bv2.second.y );
	// Z
	res.first.z = max( bv1.first.z, bv2.first.z );
	res.second.z = min( bv1.second.z, bv2.second.z );
	
	return (CMP(res.first.x, res.second.x) <= 0 && CMP(res.first.y, res.second.y) <= 0
		&& CMP(res.first.z, res.second.z) <= 0);
}
	
//! Collision between Shapes (it will be removed when the perfect collision is made)
bool Collision::collision(Shape * s1, Shape * s2) {
	return collision(s1->getBoundingVolume(), s2->getBoundingVolume());
}
